package com.asl.website.solution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.solution.domain.TransportSolutionDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.solution.domain.BizTransportSolution;
import com.asl.website.solution.service.IBizTransportSolutionService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 运输解决方案Controller
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/solution/solution")
public class BizTransportSolutionController extends BaseController
{
    @Autowired
    private IBizTransportSolutionService bizTransportSolutionService;

    /**
     * 获取所有运输解决方案（支持多语言）
     */
    @GetMapping("/content")
    public AjaxResult listSolutions(
            @RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {

        List<BizTransportSolution> solutions = bizTransportSolutionService.selectBizTransportSolutionList(new BizTransportSolution());
        if (solutions.isEmpty()) {
            return AjaxResult.error("未配置运输解决方案");
        }

        return AjaxResult.success(new TransportSolutionDTO(solutions, acceptLanguage));
    }

    /**
     * 查询运输解决方案列表
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTransportSolution bizTransportSolution)
    {
        startPage();
        List<BizTransportSolution> list = bizTransportSolutionService.selectBizTransportSolutionList(bizTransportSolution);
        return getDataTable(list);
    }

    /**
     * 导出运输解决方案列表
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:export')")
    @Log(title = "运输解决方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizTransportSolution bizTransportSolution)
    {
        List<BizTransportSolution> list = bizTransportSolutionService.selectBizTransportSolutionList(bizTransportSolution);
        ExcelUtil<BizTransportSolution> util = new ExcelUtil<BizTransportSolution>(BizTransportSolution.class);
        util.exportExcel(response, list, "运输解决方案数据");
    }

    /**
     * 获取运输解决方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizTransportSolutionService.selectBizTransportSolutionById(id));
    }

    /**
     * 新增运输解决方案
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:add')")
    @Log(title = "运输解决方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTransportSolution bizTransportSolution)
    {
        return toAjax(bizTransportSolutionService.insertBizTransportSolution(bizTransportSolution));
    }

    /**
     * 修改运输解决方案
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:edit')")
    @Log(title = "运输解决方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTransportSolution bizTransportSolution)
    {
        return toAjax(bizTransportSolutionService.updateBizTransportSolution(bizTransportSolution));
    }

    /**
     * 删除运输解决方案
     */
    @PreAuthorize("@ss.hasPermi('solution:solution:remove')")
    @Log(title = "运输解决方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizTransportSolutionService.deleteBizTransportSolutionByIds(ids));
    }
}
